#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
libtravian
==========

Description here later...
"""

DEBUG=False

from connection import Connection
from analyse import Analyse

class Travian:
    source = None
    Perfil = {}

    def __init__(self, server, user_agent, uname, upass):
        self.server = server
        self.uname = uname

        self.Connection = Connection(server, user_agent, uname, upass)
        if self.Connection.Login():
            self.source = self.Connection.source

            self.Analyse = Analyse(self.source)
            self.getPerfil()


    def getPerfil(self):
        if len(self.Perfil)==0:
            if not self.Connection.MyBrowser('spieler.php',0,'url'):
                return False
            source = self.Connection.source
            url = self.Connection.url
            self.Perfil = self.Analyse.getPerfil(source, url)
            resp=self.Connection.MyBrowser("dorf1.php",0,"url")
            return self.Perfil
        else:
            return self.Perfil


    def getVillages(self):
        if self.Analyse.villagesIdx:
            return self.Analyse.villagesIdx, self.Analyse.villages
        else:
            return self.Perfil['villages']


    def LoginOk(self):
        return self.Connection.loginok


